<template>
    <div>
        <div v-for="api in apiList" :key="api.id" class="api-item">
            <div>
                <div class="api-item-right">
                    <div>
                        <Tooltip :content="api.requestMethod" placement="top">
                            <Avatar size="large" :style="methodColor(api)">{{api.requestMethod.substring(0, 3)}}</Avatar>
                        </Tooltip>
                    </div>
                    <div style="font-size: 14px; font-weight: bold">{{api.url}}</div>
                    <div>{{api.description}}</div>
                </div>
            </div>
            <div>
                <div>{{api.responseObjType}}</div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data(){
          return {
              id: this.$route.params.id,
              apiList: [],
              params: {
                  filters: []
              }
          }
        },
        created(){
            this.$axios.post('/mdo/api/v1/apiBase/pages', {
                filters: [{
                    field: 'appId',
                    operator: 'EQ',
                    value: this.id
                }]
            }).then(res => {
                res.data.list.forEach(item => {
                    this.$axios.post('/mdo/api/v1/apiInterface/pages', {
                        filters: [{
                            field: 'apiBaseId',
                            operator: 'EQ',
                            value: item.id
                        }],
                        orders: [{
                            field: 'tableId'
                        }, {
                            field: 'url'
                        }]
                    }).then(res => {
                        this.apiList = this.apiList.concat(res.data.list);
                    })
                });
            });
        },
        methods:{
            methodColor(api){
                if (api.requestMethod === 'POST') {
                    return {'background-color': '#19be6b'}
                } else if (api.requestMethod === 'PUT') {
                    return {'background-color': '#ff9900'}
                } else if (api.requestMethod === 'GET') {
                    return {'background-color': '#2db7f5'}
                } else if (api.requestMethod === 'DELETE') {
                    return {'background-color': '#f93e3e'}
                }
            }
        }
    }
</script>

<style lang="less" scoped>
    .api-item{
        padding: 8px 0;
        height: 64px;
        border-bottom: 1px solid @border-color-base;
        display: flex;
        align-items: center;
        justify-content: space-between;

        &:last-child{
            border-bottom: none;
        }

        .api-item-right{
            display: flex;
            align-items: center;
            &>div{
                margin-right: 12px;
            }
        }
    }
</style>